/**
* @author:kellen
* @contact:xiekellen@hotmail.com
* @company:achivo-gz
* @created on:
* @modified on:
*/

package com.sasis.dao.ibatis;

import java.util.List;

import com.sasis.dao.ibatis.BaseDaoiBATIS;
import com.sasis.model.VipType;
import com.sasis.dao.VipTypeDao;

import org.springframework.orm.ObjectRetrievalFailureException;

public class VipTypeDaoiBatis extends BaseDaoiBATIS implements VipTypeDao {

    /**
     * @see com.sasis.dao.VipTypeDao#getVipTypes(com.sasis.model.VipType)
     */
    public List getVipTypes(final VipType vipType) {
          return getSqlMapClientTemplate().queryForList("getVipTypes", vipType);
    }

    /**
     * @see com.sasis.dao.VipTypeDao#getVipType(Integer id)
     */
    public VipType getVipType(Integer id) {
        VipType vipType = (VipType) getSqlMapClientTemplate().queryForObject("getVipType", id);
        return vipType;
    }

    /**
     * @see com.sasis.dao.VipTypeDao#saveVipType(VipType vipType)
     */    
    public void saveVipType(final VipType vipType) {
        Integer id = vipType.getId();
        // check for new record
        if (id == null) {
            id = (Integer) getSqlMapClientTemplate().insert("addVipType", vipType);
        } else {
            getSqlMapClientTemplate().update("updateVipType", vipType);
        }
        if( id == null ) {
            throw new ObjectRetrievalFailureException(VipType.class, id);
        }
    }

    /**
     * @see com.sasis.dao.VipTypeDao#removeVipType(Integer id)
     */
    public void removeVipType(VipType vipType) {
        getSqlMapClientTemplate().update("deleteVipType",  vipType);
    }
}
